package com.jg.controller;

import com.jg.comm.responce.PageResult;
import com.jg.comm.responce.R;
import com.jg.model.dto.OrderDTO;
import com.jg.model.dto.OrderQuery;
import com.jg.model.vo.OrderVo;
import com.jg.service.PurchaseOrdersService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 采购订单表 记录采购订单信息 前端控制器
 * </p>
 *
 * @author 86130
 * @since 2025-09-19 11:21
 */
@RestController
@RequestMapping("/purchaseOrders")
public class PurchaseOrdersController {
    @Autowired
    private PurchaseOrdersService purchaseOrdersService;

    @PostMapping("/createOrder")
    @Operation(description = "创建订单")
    @Parameter(name = "orderDTOS", description = "订单信息")
    public R createOrder(@RequestBody List<OrderDTO> orderDTOS){
        purchaseOrdersService.creatOrder(orderDTOS);
        return R.success("创建订单成功");
    }
    //订单分页查询
    @PostMapping("/page")
    @Operation(description = "订单分页查询")
    public R<PageResult<OrderVo>> page(@RequestBody OrderQuery orderQuery){
        PageResult<OrderVo> page = purchaseOrdersService.OrderPage(orderQuery);
        return R.success(page);
    }
    //发货
    @GetMapping("/updateStatus/{orderId}/{supplierId}")
    @Operation(description = "更改订单状态-发货")
    public R updateStatus(@PathVariable String orderId,@PathVariable Integer supplierId){
        purchaseOrdersService.updateStatus(orderId,supplierId);
        return R.success("更新成功");
    }
    //收货
    @GetMapping("/receive/{orderId}/{supplierId}")
    @Operation(description = "收货")
    public R receive(@PathVariable String orderId, @PathVariable Integer supplierId){

        purchaseOrdersService.receive(orderId,supplierId);
        return R.success("收货成功");
    }
    //退货
    @GetMapping("/returnGoods/{orderId}/{supplierId}")
    @Operation(description = "退货")
    public R returnGoods(@PathVariable String orderId, @PathVariable Integer supplierId){
        purchaseOrdersService.returnGoods(orderId,supplierId);
        return R.success("退货成功");
    }
    //根据供应商ID和订单月份查询供应商订单信息
    @GetMapping("/supplierOrderGroup")
    @Operation(description = "根据供应商ID和订单月份查询供应商订单信息")
    public R<List<OrderVo>> supplierOrderGroup(String supplierId, String month){
        List<OrderVo> orderVos = purchaseOrdersService.queryOrderBySupplierIdAndMonth(supplierId, month);
        return R.success(orderVos);
    }
}
